#include <EndState.h>

template<> EndState* Ogre::Singleton<EndState>::ms_Singleton = 0;

void EndState::enter ()
{
  _root = Ogre::Root::getSingletonPtr();

  // Se recupera el gestor de escena y la cámara.
  _sceneMgr = _root->getSceneManager("SceneManager");
  _camera = _sceneMgr->getCamera("MainCamera");
  _viewport = _root->getAutoCreatedWindow()->getViewport(0);
  // Nuevo background colour.
  _viewport->setBackgroundColour(Ogre::ColourValue(0.75, 0.0, 0.0));

  _exitGame = false;
}

void EndState::exit()
{
  // Se restaura el color anterior.
  _viewport->setBackgroundColour(Ogre::ColourValue(0.0, 0.0, 0.0));
}

void EndState::pause()
{
}

void EndState::resume()
{
}

bool EndState::frameStarted(const Ogre::FrameEvent& evt)
{
  return true;
}

bool EndState::frameEnded(const Ogre::FrameEvent& evt)
{
  return not _exitGame;
}

void EndState::keyPressed(const OIS::KeyEvent& e)
{
  popState();
  popState();
}

void EndState::keyReleased(const OIS::KeyEvent& e) {}

void EndState::mouseMoved(const OIS::MouseEvent& e) {}

void EndState::mousePressed(const OIS::MouseEvent& e, OIS::MouseButtonID id) {}

void EndState::mouseReleased(const OIS::MouseEvent& e, OIS::MouseButtonID id) {}

EndState* EndState::getSingletonPtr()
{
  return ms_Singleton;
}

EndState& EndState::getSingleton()
{ 
  assert(ms_Singleton);
  return *ms_Singleton;
}
